package com.zut.wx.handler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class MsgHandlerFactory implements InitializingBean {
    @Resource
    private List<WxChatMsgHandle> list;

    Map<WxChatMsgTypeEnums,WxChatMsgHandle> MsgHandler=new HashMap<>();

    public WxChatMsgHandle getHandleByType(String type){

        return MsgHandler.get(WxChatMsgTypeEnums.getEnumByType(type));
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        for (WxChatMsgHandle wxChatMsgHandle: list) {
            MsgHandler.put(wxChatMsgHandle.getEnumByType(),wxChatMsgHandle);
        }
    }
}
